package com.euc.springbootframework.entity;


import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Field;

public abstract class AbstractMongoPersistable {
    @Id
    @Field("ID")
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public boolean isNew() {
        return (null == getId());
    }

    public boolean equals(Object obj) {
        if (null == obj) {
            return false;
        }

        if (this == obj) {
            return true;
        }

        if (!(super.getClass().equals(obj.getClass()))) {
            return false;
        }

        AbstractMongoPersistable that = (AbstractMongoPersistable) obj;

        return ((null == getId()) ? false : getId().equals(that.getId()));
    }

    public int hashCode() {
        int hashCode = 17;

        hashCode += ((null == getId()) ? 0 : getId().hashCode() * 31);

        return hashCode;
    }
}
